﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Code.Models;

namespace Code.BLL
{
    public class MessageManage:ManageBase<Message>
    {
        /// <summary>
        /// 添加留言
        /// </summary>
        public int Add(Message msg)
        {
            int rs = 0;
            rs = base.Insert<Message>(new { msg.ContactInfo, msg.Title, msg.Content, msg.Name, msg.Language });
            return rs;
        }

        public Message Read(long id)
        {
            var data = base.GetTable<Message>().FirstOrDefault(p => p.ID == id);
            if (data != null && data.State == MessageState.New.ValueShort())
            {
                base.Update<Message>(new { State = (short)MessageState.Read }, new { data.ID });
            }
            return data;
        }

        /// <summary>
        /// 删除留言
        /// </summary>
        public int Del(params long[] ids)
        {
            int rs = 0;
            rs = base.Delete<Message>(new { ID = new ComparValue(Comparison.In, ids) });
            return rs;
        }
    }
}
